//
//  WPCLeftSidebarCell.swift
//  Wallpaper.co
//
//  Created by zhou_yuepeng on 2017/9/26.
//  Copyright © 2017年 www.dahuatech.com. All rights reserved.
//

import UIKit

class WPCLeftSidebarCell: UICollectionViewCell {
    var title:UILabel?;
    var icon:UIImageView?;
    
    var categoryItem:WPCCategoryItem? {
        didSet {
            title?.text = categoryItem?.title;
            
            var iconShow = false;
            if categoryItem?.title == "New" {
                icon?.image = UIImage.init(named: "new");
                iconShow = true;
            }
            else if categoryItem?.title == "Best" {
                icon?.image = UIImage.init(named: "best");
                iconShow = true;
            }
            else if categoryItem?.title == "Favorites" {
                icon?.image = UIImage.init(named: "favorite");
                iconShow = true;
            }
            
            layoutWithMasonry(iconShow: iconShow);
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame);
        
        title = UILabel();
        title?.isHidden = true;
        title?.textAlignment = NSTextAlignment.center;
        title?.font = UIFont.init(name: "Helvetica", size: 12);
        self.addSubview(title!);
        
        icon = UIImageView();
        icon?.isHidden = true;
        self.addSubview(icon!);
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func layoutWithMasonry(iconShow:Bool) {
        icon?.isHidden = !iconShow;
        title?.isHidden = iconShow;
        
        icon!.makeConstraints({ (make) in
            make!.size.equalTo()(CGSize.init(width: 55, height: 55));
            make!.center.equalTo()(self);
        })
       
        title!.makeConstraints({ (make) in
            make!.left.equalTo()(self);
            make!.top.equalTo()(self);
            make!.size.equalTo()(self);
        })
 
    }
}
